package com.cooper.mediadb.local;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;

import com.cooper.mediadb.Actor;
import com.cooper.mediadb.Media;

public abstract class LocalMedia extends Media{

	/**
	 * 
	 */
	private static final long serialVersionUID = 7827930334056808995L;
	
	public static String fileNameToTitle(File file) {
		String result = file.getName();
		if (file.isFile()) {
			result = result.replaceAll("\\.\\w+?$", "");
		}
		return result.replaceAll("\\.\\d+?[pP].*$", "")
				.replaceAll("\\.BluRay.*$", "")
				.replaceAll("\\.[xX]\\d+?.*$", "").replace(".", " ");
	}
	
	private static Map<String, String> videoMIMETypes = null;

	public static Map<String, String> videoMIMETypes() {
		if (videoMIMETypes == null) {
			videoMIMETypes = new HashMap<String, String>();
			videoMIMETypes.put(".3gp", "video/3gpp");
			videoMIMETypes.put(".asf", "video/x-ms-asf");
			videoMIMETypes.put(".avi", "video/x-msvideo");
			videoMIMETypes.put(".m4u", "video/vnd.mpegurl");
			videoMIMETypes.put(".m4v", "video/x-m4v");
			videoMIMETypes.put(".mov", "video/quicktime");
			videoMIMETypes.put(".mp4", "video/mp4");
			videoMIMETypes.put(".mpe", "video/mpeg");
			videoMIMETypes.put(".mpeg", "video/mpeg");
			videoMIMETypes.put(".mpg", "video/mpeg");
			videoMIMETypes.put(".mpg4", "video/mp4");
			videoMIMETypes.put(".rmvb", "video/x-pn-realvideo");
			videoMIMETypes.put(".ra", "video/x-pn-realvideo");
			videoMIMETypes.put(".ram", "video/x-pn-realvideo");
			videoMIMETypes.put(".wmv", "video/x-ms-wmv");
			videoMIMETypes.put(".mkv", "video/x-matroska");
			videoMIMETypes.put(".vob", "video/vob");
			videoMIMETypes.put(".flv", "video/x-flv");			
			videoMIMETypes.put(".f4v", "video/mp4");
			videoMIMETypes.put(".hlv", "video/x-hlv");
			videoMIMETypes.put(".pfv", "video/*");
			//other online format
		}
		return videoMIMETypes;
	}

	public static boolean isVideoFile(File f) {
		if (f.isDirectory()) {
			return false;
		}
		return isVideoFile(f.getName());
	}

	public static boolean isVideoFile(String path) {
		if (path == null || "".equals(path) || path.lastIndexOf(".") < 0) {
			return false;
		}
		String end = path.trim()
				.substring(path.lastIndexOf("."), path.length()).toLowerCase();
		return videoMIMETypes().get(end) != null;
	}	
	
	
	protected List<Actor> actors;

	@Override
	public boolean detailsIsReady() {
		return true;
	}

	@Override
	public void prepareDetails(Context context) {		
	}

	@Override
	public void cancelDetails() {		
	}

	@Override
	public List<Actor> getActors() {
		return actors;
	}
	
	
	
	public abstract String getFanartPath();
	
	public abstract String getPosterPath();

}
